﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Entity;
using vdos.jobseeker.Utils;
using vdos.jobseeker.Model;

namespace vdos.jobseeker.AdminCP.Company
{
    public partial class company_new : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["USER"] == null) { Response.Redirect("/login.aspx"); }
            //else
            //{
            //    if (hash1way.CheckPermission(hash1way.GetPermission(Session["USER"].ToString()), "SYSADMIN") == false)
            //    {
            //        if (hash1way.CheckPermission(hash1way.GetPermission(Session["USER"].ToString()), "HOMEPAGE") == false)
            //        {
            //            Response.Redirect("/message_box.aspx?why=1&msg=5");
            //        }
            //    }
            //}

            if (!Page.IsPostBack)
            {
                
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            addCompany();
            Response.Redirect("/Company/company_all_published.aspx");
        }

        protected void addCompany()
        {
            try
            {
                string sLogo = LogoFilePath.Value;
                string sCompanyName = CompanyName.Value;
                string sCompanyDetail = CompanyDetail.Value;

                //string sSQL = "Insert Company values (N'"+sCompanyName+"',N'"+sCompanyDetail+"','"+sLogo+"')";
                //DataHelper.ExecuteNonQuery(sSQL,true);

                var context = new jobseekerEntities();

                var company = new Model.Company();

                company.CompanyLogo = sLogo;
                company.CompanyName = sCompanyName;
                company.CompanyDetails = sCompanyDetail;

                context.AddToCompany(company);
                context.SaveChanges();
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        
    }
}
